<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\BaseController;
use app\model\SpecsValue;
use think\Request;

class Specs extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        $params=\request()->param();
        $data=\app\model\Specs::create($params);
        $res['id']=$data->id;
        $res['specs_name']=$data->specs_name;
        $res['products_id']=$data->products_id;

        return $this->success($res);
    }



    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update($id)
    {
        $data=\request()->param();
        \app\model\Specs::where('id',$id)->update($data);
        return $this->success();
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        \app\model\Specs::where('id',$id)->delete();
        SpecsValue::where('specs_id',$id)->delete();
        return $this->success();
    }
}
